import React from 'react';
import ReactDOM from 'react-dom';
import Navv from './nav.jsx';
import '../../static/tero/public.less';
import u from '../../common.js'
import { message } from 'antd';
import $ from 'jquery';

class Public extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            names: '',
            flag: true,
            index: 0,
            search: [{ src: "../../static/image/tou_fifty.png", title: '宋中继' }, { src: "../../static/image/tou_fifty.png", title: '王小筱' }, { src: "../../static/image/tou_fifty.png", title: '鲁达' }, { src: "../../static/image/tou_fifty.png", title: '宋中继' }, { src: "../../static/image/tou_fifty.png", title: '钱度' }, { src: "../../static/image/tou_fifty.png", title: '李四' },],
            base: [],
            block: 0,
            myname: '添加微信号',
            mynumber: 11,
            startTime: u.getDate(0, false),
            endTime: u.getDate(0, true),
            myname: '添加微信号',
            mynumber: 11,
            top: '-8px',
            size: 10,
            page: 1,
            filter: [],
            source:'',
            sizeFlag:false,
            moreFlag:false
        }
    }

    componentWillMount() {
        this.getNameList()

    }
    publicnumder(flag) {
        let data = {
            // "startTime": this.state.startTime,
            // "endTime": this.state.endTime,
            "page": this.state.page,
            "size": this.state.size,
            webSiteType: '14',
            source: this.state.source,
            sortField:'poTime',
            sortType:'DESC'
        };
        u.queryList(data, (data) => {
            let arr = flag ? this.state.base.slice(0).concat(data.data) : data.data
            this.state.page == 1 && data.data.length == 0?
            this.setState((prevState, props) => ({
                base: arr,
                size: data.data.length,
                sizeFlag:true,
                moreFlag:false
            })): this.setState((prevState, props) => ({
                base: arr,
                size: data.data.length,
                sizeFlag:false,
                moreFlag:true
            }))
        },()=>{
            this.setState((prevState, props) => ({
                sizeFlag:false,
                moreFlag:true
            }))
        })
    }
    add() {
        this.state.size == 10?
        this.setState((prevState, props) => ({
            page: this.state.page + 1
        }), () => {
            this.publicnumder(true)
        }):message.success( '没有更多数据了', [1], )
    }
    handle(index,content) {
        localStorage.setItem('content',content);
        const w = window.open('about:blank');
        w.location.href = u.testurl+'/tero/d?' + this.state.base[index].id
        sessionStorage.setItem('keyword','6')
        sessionStorage.setItem('keysub','sub3')

    }
    blockContent(index, val) {  //导航点击后的回调
        if (val || val == '') {
            this.setState((prevState, props) => ({
                filter: this.state.names.filter((item) => {
                    return item.includes(val)
                })
            }))
        } else {
            this.setState((prevState, props) => ({
                block: index,
                page: 1,
                size: 10,
                source: this.state.names[index],
                sizeFlag:false
            }), () => {
                this.publicnumder(false)
            })
        }


    }
    getNameList() { //获取导航列表
        u.publickList(data => {
            this.setState((prevState, props) => ({
                names: data.data,
                filter: data.data,
                source:data.data[0]
            }), () => {
                u.setStore('gzName', this.state.names[0])
                this.publicnumder(false)
            })
            // $('.nav_father>.nav').css('width', data.data.length * 96 + 'px')

        })
    }
    render() {
        return (
            <div className='tero_father'>
                <Navv names={this.state.names} blockContent={this.blockContent.bind(this)} myname={this.state.myname} mynumber={this.state.mynumber} top={this.state.top} filter={this.state.filter} />
                {

                    <div className={this.state.sizeFlag?'nav_bc nav_bc_active nav_bc_activee':'nav_bc nav_bc_active'}>
                        {
                            this.state.base.map((itemm, indexx) => {
                                return (<div className='nav_b_son' key={indexx}>
                                    <div className='top'><h3 onClick={() => {
                                        this.handle(indexx,itemm.content)
                                    }} dangerouslySetInnerHTML={{__html:itemm.title}}></h3><span>{u.unixTime(itemm.poTime)}</span></div>
                                    <div className='bottom'><p dangerouslySetInnerHTML={{__html:itemm.content}}>{}</p><div className='border_bottom'></div></div>
                                </div>)
                            }) 
                        }
                        <div className='add'><span onClick={() => {
                            this.add()

                        }} style={{display:this.state.moreFlag?'block':'none'}}>{this.state.size == 10?'查看更多>>':'没有更多数据'}</span></div>

                    </div>

                })

            }

            </div>
        )
    }
}




export default Public